define(function (require, exports, module) {

  require("mixins/global.mixins.js");
  var mCard = require('andrew/card/index.js')


  var api = require('service/api.js');

  var pageVue = new Vue({
    data: {
      tableList: [],
      searchForm: {
        id: null,
        name: null,
        parentCategoryId: null,
        categoryId: null,
        dataFlag: 1
      },
      dataFlagEnum: [],
      OneCategoryList: [],
      TwoCategoryList: [],
      selectedOptions: [],
      formCollapse: false
    },
    mounted: function () {
      this.getOneCategoryList();
      this.getDataList();

      console.log(this.Enum);
    },
    methods: {
      getOneCategoryList: function () {
        var curPageVue = this;

        api.queryCategoryList({
          params: {
            pId: 0
          },
          callBack: function (res) {
            curPageVue.OneCategoryList = res;
            console.log('SimpleCategoryList');
            console.log(res);

          }
        })
      },
      getChildrenCategoryList: function (id) {
        var curPageVue = this;

        api.queryCategoryList({
          data: {
            pId: id
          },
          success: function (res) {
            curPageVue.TwoCategoryList = res;
            console.log('SimpleCategoryList');
            console.log(res);

          }
        })
      },
      categoryChange: function (val) {
        this.twoCategoryId = null;
        this.TwoCategoryList = [];
        this.getChildrenCategoryList(val);
      },
      handleChange(value) {
        console.log(value);
      },
      clearSearch: function () {
        this.searchForm.id = null;
        this.searchForm.name = null;
        this.searchForm.dataFlag = null;
        this.searchForm.categoryId = null;
        this.selectedOptions = [null];
      },
      clearThenSearch: function () {
        this.clearSearch();
        this.getDataList();
      },
      toggleSearhBodyCollapse: function () {
        this.formCollapse = !this.formCollapse;
      },
      onSubmit() {
        this.getDataList();
      },
      getDataList: function () {

        var curPageVue = this;

        var query = {};

        // 还是一个个赋值吧  
        // for (x in option.params) {
        //     if (option.params.hasOwnProperty(x) && option.params[x] != null && option.params[x] != "") {
        //         query[x] = option.params[x];
        //     }
        // }


        if (curPageVue.searchForm.id != null && curPageVue.searchForm.id.length > 0) {
          query['id'] = curPageVue.searchForm.id;
        }
        if (curPageVue.searchForm.name && curPageVue.searchForm.name.length > 0) {
          query['name'] = curPageVue.searchForm.name;
        }
        if (curPageVue.searchForm.dataFlag != null && curPageVue.searchForm.dataFlag > 0) {
          query['dataFlag'] = curPageVue.searchForm.dataFlag;
        }
        if (curPageVue.searchForm.categoryId != null && curPageVue.searchForm.categoryId > 0) {
          query['categoryId'] = curPageVue.searchForm.categoryId;
        }

        console.log(query);

        // curPageVue.tableList = [{
        //   "id": 7,
        //   "title": "立方停车介绍",
        //   "headImgUrl": "https://pic3.40017.cn/line/admin/2015/11/05/14/FuHnZU.jpg",
        //   "summary": "",
        //   "categoryId": 3,
        //   "categoryName": "立方停车介绍",
        //   "dataFlag": 1,
        //   "categoryIntroduce": 1
        // }];
        query.dataFlag=-1;
        query.id=-1;
        api.getArtList({
          data: query,
          success: function (res) {
            curPageVue.tableList = res;
            console.log(res);
          }
        })
      },
      handleEdit(index, row) {
        console.log(index, row)
        pageVue = this

        var id = row.id || 0

        // iframe窗
        var index = layer.open({
          type: 2,
          title: '文章基本信息修改',
          shade: [0],
          area: ['80%', '90%'],
          content: ['05_artEdit.html?id=' + id], // iframe的url，no代表不显示滚动条
          end: function () { // 此处用于演示
            // alert(0)

            pageVue.getDataList()
          }
        })
      },
      handleChapterList(index, row) {
        console.log(index, row)

        top.window.href = "'06_chapterList.html'";

      },

      handleDelete(index, row) {
        console.log(index, row)
      },

      handleCommand(command) {
        if (command == "a") {
          window.location.href = "06_chapterList.html";
        }
      }
    }

  }).$mount('#app')
})
